#include "triangle.hpp"

bool Triangle::Intersect(Ray& intersectRay, double& t)
{

	
	if (!(Plane::Intersect(intersectRay,t))) return false;
		
		
		Vector3D intersect=intersectRay.startPoint + t*intersectRay.direction;
		Vector3D n=normalize((position2-position)*(position3-position2));
		
		if ((((position2 - position)*(intersect - position)) & n) <= 0) return false;
		if ((((position3 - position2)*(intersect - position2)) & n) <= 0) return false;
		if ((((position - position3)*(intersect-position3)) & n) <= 0) return false;
		return (t>Defined::GeomThreshold);
			
}

